package edu.progra2.ventas.action;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import edu.progra2.common.util.Utilitario;
import edu.progra2.ventas.model.Empleado;


/*
 * http://localhost:8080/sesion6-struts2-hr/
 */
@Action(value="regEmp",
results={@Result(name="exito", 
location="/message.jsp"),
@Result(name="error", 
location="/regEmp.jsp")
} )
public class RegistrarEmpleadoAction {
	private Empleado empleado;
	private String message;
	
	public String execute(){
		String result="error";
		
			EntityManager em=
					Utilitario.getInstance().getEntityManager();
			EntityTransaction tx=em.getTransaction();
			try{
				tx.begin();
				em.persist(empleado);
				tx.commit();
				result="exito";
				message = "El Empleado a sido Registrado Satisfactoriamente";
			}catch(Exception ex){
				ex.printStackTrace();
				tx.rollback();
				message = "El Empleado no a sido Registrado Satisfactoriamente";
			}
		
		return result;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Empleado getEmpleado() {
		return empleado;
	}

	public void setEmpleado(Empleado empleado) {
		this.empleado = empleado;
	}


	
	
	
	
}
